﻿using BF;
using BF.UI;
using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;


public abstract class BaseDialog : Dialog {
    protected Vector3 originScale { get; private set; }
    protected Vector2 originPos { get; private set; }

    private static AnimationCurve curveOpen;
    private static AnimationCurve curveClose;

    public void Reset() {
        this.gameObject.name = this.GetType().Name;
    }

    protected override void Awake() {
        base.Awake();
    }

    protected override void OnEnable() {
        if (content != null) {
            originScale = content.localScale;
            originPos = content.anchoredPosition;
        }
        base.OnEnable();
    }

    protected override Tweener GetOpenAnimation() {
        if (curveOpen == null)
        {
            AnimationCurveObj co = Resources.Load<AnimationCurveObj>("Dialog/_CurveOpen");
            curveOpen = co.curve;
            Resources.UnloadAsset(co);
        }

        content.transform.localScale = new Vector3(0.6f, 0.6f, 0.6f);
        return content.DOScale(1, 0.4f).SetEase(curveOpen);
    }

    protected override Tweener GetCloseAnimation() {
        if (curveClose == null)
        {
            AnimationCurveObj co = Resources.Load<AnimationCurveObj>("Dialog/_CurveClose");
            curveClose = co.curve;
            Resources.UnloadAsset(co);
        }

        return content.DOScale(0.5f, 0.25f).SetEase(curveClose);
    }

    protected override void OnDisable() {
        base.OnDisable();
        if (content != null) {
            content.localScale = originScale;
            content.anchoredPosition = originPos;
        }
    }

    protected override void PlayOpenSound() {

    }

    protected override void PlayCloseSound() {

    }
}
